package com.news.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.news.entity.User;
import com.news.service.UserService;


@WebServlet("/adminuseredit")
public class AdminUserEditServlet extends HttpServlet {

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 1.获取参数
		request.setCharacterEncoding("UTF-8");
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String role = request.getParameter("role");
		String sex = request.getParameter("sex");
		String age = request.getParameter("age");
		String id = request.getParameter("id");
		User user = new User();
		user.setUsername(username);
		user.setPassword(password);
		user.setRole(role);
		user.setSex(Integer.parseInt(sex));
		user.setAge(Integer.parseInt(age));
		user.setId(Integer.parseInt(id));
				
		// 2.修改用户信息
		UserService userService = new UserService();
		boolean flag = userService.editUser(user);
		if (flag) {
			response.sendRedirect(request.getContextPath()+"/adminuserlist");
		}
	}
}
